package com.tyut.homework.controller;

import com.tyut.homework.pojo.StuDor;
import com.tyut.homework.repository.StuDorRepository;
import com.tyut.homework.response.ServerResponse;
import com.tyut.homework.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api("学生宿舍")
@RestController
@RequestMapping("/studor")
public class StuDorController {

    @Autowired
    private StuDorRepository stuDorRepository;
    @Autowired
    private StudentService studentService;
    @ApiOperation("添加学生到宿舍")
    @PostMapping("/add")
    public ServerResponse addStuInDor(@RequestParam Integer aptId,
                                      @RequestParam Integer dorId,
                                      @RequestParam Integer stuId){
        StuDor stuDor = new StuDor();
        stuDor.setStuId(aptId);
        stuDor.setDorId(dorId);
        stuDor.setStuId(stuId);
        stuDorRepository.save(stuDor);
        // 修改学生状态
        studentService.updateStatus(stuId);
        return ServerResponse.createBySuccess();
    }
}
